package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Score;

public class ScoreDao extends SuperDao {

	/**
	 * 
	 * 保存会员积分记录
	 */
	public void add(Score score) {
		super.save(score);
	}

	public List<Object> getScorePage(int index, Score score) {
		return null;
	}

	public int getScoreceLine(Score score) {
		return 1;
	}

	/**
	 * 
	 * 删除单条会员积分记录
	 */
	public void deleteById(Score score) {
		super.delete(score);
	}

	/**
	 * 
	 * 根据时间和member查询
	 */
	public Object getByTimeAndMember(Score score) {
		String sql = "from Score where createTime=?  and memberId=?";
		List<Object> objects = super.getObject(sql,
				new Object[] { score.getCreateTime(), score.getMemberId() });
		if (objects.size() > 0) {
			return objects.get(0);
		}
		else {
			return null;
		}
	}

	/**
	 * 查询会员在某企业的积分总数
	 */
	public Object getEaScore(Score score) {
		String sql = "select SUM(numer) from Score where eaId = ? and memberId=?";
		List<Object> objects = super.getObject(sql,
				new Object[] { score.getEaId(), score.getMemberId() });
		if (objects.size() > 0) {
			return objects.get(0);
		}
		else {
			return null;
		}
	}
	
	/**
	 * 查询会员的积分总数
	 */
	public Object getTotleEaScore(Score score) {
		String sql = "select SUM(numer) from Score where memberId=?";
		List<Object> objects = super.getObject(sql,
				new Object[] { score.getMemberId() });
		if (objects.size() > 0) {
			return objects.get(0);
		}
		else {
			return null;
		}
	}
	
	/**
	 * 根据memberId查询会员记录
	 */
	public List<Object> getScoreLogByMemberId(Long memberId) {
		String sql = "from Score where memberId=?";
		return getObject(sql, new Object[]{ memberId });
	}
	
}
